package com.net.xpay.web.controller.merchant;

import com.google.common.base.Preconditions;
import com.net.common.model.ResultData;
import com.net.common.model.ResultPagedList;
import com.net.xpay.common.domain.User;
import com.net.xpay.core.domain.UserWithdrawRecord;
import com.net.xpay.core.manager.UserWithdrawRecordManager;
import com.net.xpay.core.model.UserWithdrawModel;
import com.net.xpay.core.model.UserWithdrawRecordSearchModel;
import com.net.xpay.core.service.UserWithdrawService;
import com.net.xpay.web.secutiry.RequestUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 86188
 */
@RestController
@Slf4j
@RequestMapping("/merchant/user-withdraw")
@Api(tags = "商户/用户提现", description = "商户 用户提现 net")
public class UserWithdrawController {

    @Autowired
    private UserWithdrawRecordManager userWithdrawRecordManager;

    @Autowired
    private UserWithdrawService userWithdrawService;

    /**
     * 搜索
     */
    @ApiOperation("搜索")
    @PostMapping("/search")
    public ResultPagedList<UserWithdrawRecord> search(@ApiIgnore @RequestUser User merchant, @RequestBody UserWithdrawRecordSearchModel searchModel) {
        Preconditions.checkArgument(searchModel != null);
        searchModel.setUserId(merchant.getId());

        List<UserWithdrawRecord> records = userWithdrawRecordManager.search(searchModel);
        long count = userWithdrawRecordManager.searchCount(searchModel);

        return new ResultPagedList<>(records, count, searchModel);
    }

    @ApiOperation("新增提现")
    @PostMapping("/save")
    public ResultData<UserWithdrawRecord> addUserWithdrawRecord(@ApiIgnore @RequestUser User merchant, @RequestBody UserWithdrawModel model) {
        UserWithdrawRecord userWithdrawRecord = userWithdrawService.addUserWithdrawRecord(merchant, model);

        return new ResultData<>(userWithdrawRecord);
    }


}
